$.fn.extend({
    animateCss: function (animationName,fuc) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        this.addClass('animated ' + animationName).one(animationEnd, function() {
            $(this).removeClass('animated ' + animationName);
            if(fuc) fuc();
        });
    }
});

$(function () {
    (function () {
       setTimeout(function () {
           $('.build a').each(function () {
               $(this).fadeIn(500);
               var arr = [0,250,500,1000],
                   index = $('.build a').index($(this)),
                   delay = index?'delay-'+arr[index]:'';
               $(this).addClass('animated c-pulse infinite '+delay)
           });
       },1000);
       setTimeout(function () {
           $('.earth-feiji').fadeIn();
       },2000);
    })()

    var swiper = new Swiper('.swiper-container',{
        initialSlide : 0,
        // effect:'coverflow',
        // speed : 100,
        direction : 'vertical',
        onlyExternal : true,
        onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
            console.log(0)
            swiperAnimateCache(swiper); //隐藏动画元素
            swiperAnimate(swiper); //初始化完成开始动画
        },
        onSlideChangeEnd: function(swiper){
            swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
            if(swiper.activeIndex == 1){
                // player.play();
            }
            else if(swiper.activeIndex == 3){
                fragmentImg({
                    container : '.img-flex',//显示容器
                    line : 15,//多少行
                    column : 14,//多少列
                    width : $(window).width(),//显示容器的宽度
                    animeTime : 8000,//最长动画时间,图片的取值将在 animeTime*0.33 + animeTime*0.66之前取值
                    img : __uri('/src/img/img.png')//图片路径
                })
                setTimeout(function () {
                    $('.page4 .foot').fadeIn(500);
                },8000)
            }
        }
    })

    var player = videojs('video',{
        width:$(window).width(),
        height: $(window).height(),
        poster : __uri('/src/img/video-img.jpg')
    },function onPlayerReady() {
        videojs.log('Your player is ready!');
        this.on('ended', function() {
            swiper.slideTo(2);
        });
    });

    // page1
    $('.build a').on('click',function () {
        var index = $('.build').index($(this).closest('.build'));
        $('.pop-box').show().animateCss('bounceIn');
        $('.pop-cont').scrollTop(0);
        $('.pop-cont .li').eq(index).show().siblings('.li').hide();
    })

    $('.pop-box .close').on('click',function () {
        $('.pop-box').animateCss('bounceOut',function () {
            $('.pop-box').hide();
        });
    })
    
    // 跳转页面
    $('.toPage').on('click',function () {
        var page = $(this).data('page');
        swiper.slideTo(page)
        if(page==1){
            player.play();
        }
    })
})